
<template>
  <el-button
    :size="size"
    :type="type"
    :disabled="disabled"
    @click="handleClick"
  >
    <slot>{{ label }}</slot>
  </el-button>
</template>

<script>
import { hasPermission } from "@/library/index.js";
import { Message } from "element-ui";
export default {
  name: "ButtonPower",
  props: {
    label: {
      type: String,
      default: "Button",
    },
    size: {
      // 按钮尺寸
      type: String,
      default: "medium",
    },
    type: {
      // 按钮类型
      type: String,
      default: "primary",
    },
    disabled: {
      // 按钮是否禁用
      type: Boolean,
      default: false,
    },
    level: {
      // 按钮权限标识，外部使用者传入
      type: Number,
    },
  },
  data() {
    return {};
  },
  methods: {
    handleClick: function () {
      // 按钮操作处理函数
      if (this.hasPerms(this.level)) {
        this.$emit("click", {});
      } else {
        Message({
          message: "您没有此功能的操作权限",
          type: "error",
          duration: 2000,
        });
      }
    },
    hasPerms: function (level) {
      return hasPermission(level);
    },
  },
  mounted() {},
};
</script>
